package com.tulingxueyuan.mall.modules.pms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tulingxueyuan.mall.dto.ProductDTO;
import com.tulingxueyuan.mall.modules.pms.mapper.PmsProductCategoryMapper;
import com.tulingxueyuan.mall.modules.pms.model.PmsProductCategory;
import com.tulingxueyuan.mall.dto.HomeMenusDTO;
import com.tulingxueyuan.mall.modules.pms.service.PmsProductCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tulingxueyuan.mall.modules.sms.model.SmsHomeAdvertise;
import com.tulingxueyuan.mall.modules.sms.service.SmsHomeAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 产品分类 服务实现类
 * </p>
 *
 * @author XuShu
 * @since 2021-03-14
 */
@Service
public class PmsProductCategoryServiceImpl extends ServiceImpl<PmsProductCategoryMapper, PmsProductCategory> implements PmsProductCategoryService {

    @Autowired
    PmsProductCategoryMapper mapper;
    @Resource
    private SmsHomeAdvertiseService smsHomeAdvertiseService;
    /**
     * 获取首页类型导航菜单
     * @return
     */
    @Override
    public List<HomeMenusDTO> getMenus() {
        return mapper.getProductWithCategory();
    }

    /**
     * 获取广告图
     * @return
     */
    @Override
    public List<SmsHomeAdvertise> getContent() {
        LambdaQueryWrapper<SmsHomeAdvertise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SmsHomeAdvertise::getType,0)
                    .eq(SmsHomeAdvertise::getStatus,1)
                    .orderByDesc(SmsHomeAdvertise::getSort);

        return smsHomeAdvertiseService.list(queryWrapper);
    }

    /**
     * 获取首页商品信息
     * @return
     */
    @Override
    public List<ProductDTO> getHomeProduct() {
        List<ProductDTO> list =  mapper.selectHomeProduct();
        return list;
    }
}
